package com.casicloud.manage.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.casicloud.manage.model.Authority;
import com.casicloud.manage.model.Menu;
import com.casicloud.manage.service.AuthorityService;
import com.casicloud.manage.service.MenuService;
import com.common.sub.util.ControllerBase;
import com.common.sub.util.PageUtil;
import com.github.pagehelper.PageInfo;
@Controller
@RequestMapping(value = "authority")
public class AuthorityController extends ControllerBase {
	
	
	@Autowired
	private AuthorityService authorityService;
	
	@Autowired
	private MenuService menuService;
	
	@RequestMapping(value = "menu", method = RequestMethod.GET)
	public String menu(Authority authority,HttpServletRequest request,HttpServletResponse response){
		
		return "authority/menu";
	}
	
	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String list(Menu menu,HttpServletRequest request,HttpServletResponse response){
		
		request.setAttribute("m", menu);
		
		return "authority/list";
	}
	
	@RequestMapping(value = "query")
	public String query(Authority authority,PageUtil pageUtil,HttpServletRequest request,HttpServletResponse response){
		PageInfo<Authority>	page  = authorityService.findByPage(pageUtil,authority);
		return this.dataToJson(page);
	}
	
	@RequestMapping(value = "update", method = RequestMethod.GET)
	public String goupdate(Authority authority,HttpServletRequest request,HttpServletResponse response){
		authority = authorityService.findByOne(authority);
		request.setAttribute("a", authority);
		return "authority/update";
	}
	
	@RequestMapping(value = "update", method = RequestMethod.POST)
	public String doupdate(Authority authority,HttpServletRequest request,HttpServletResponse response){
		
		authorityService.update(authority);
		
		return this.formSuccee();
	}
	
	@RequestMapping(value = "add", method = RequestMethod.GET)
	public String goadd(Authority authority,HttpServletRequest request,HttpServletResponse response){

		return "authority/add";
	}
	
	@RequestMapping(value = "add", method = RequestMethod.POST)
	public String doadd(Authority authority,HttpServletRequest request,HttpServletResponse response){
		
		authorityService.save(authority);
		
		return this.formSuccee();
	}
	
	@RequestMapping(value = "delete")
	public String delete(Authority authority,HttpServletRequest request,HttpServletResponse response){
		
		return "authority/update";
	}

}
